using System.IO;
using UnityEngine;

[System.Serializable]
public class Settings
{
    public int viewDistance;
    public int playerMoveSpeed;
    public int fieldOfView;
    
    public Settings(int viewDistance, int playerMoveSpeed, int fieldOfView)
    {
        this.viewDistance = viewDistance;
        this.playerMoveSpeed = playerMoveSpeed;
        this.fieldOfView = fieldOfView;
    }
    static readonly Settings defaultSettings = new Settings(16, 10, 60);
    public static void Save(Settings settings)
    {
        File.WriteAllText(Application.dataPath + "/settings.txt", JsonUtility.ToJson(settings));
    }

    public static Settings Load()
    {
        if(!File.Exists(Application.dataPath + "/settings.txt"))
        {
            return defaultSettings;
        }
        return JsonUtility.FromJson<Settings>(File.ReadAllText(Application.dataPath + "/settings.txt"));
    }
}
